<template>
  <el-table :data="orderTableData" height="700px" v-loading="loadTable" border>
    <el-table-column
      align="center"
      property="id"
      label="ID"
      width="70"
    ></el-table-column>
    <el-table-column
      align="center"
      property="grid"
      label="格号"
      width="60"
    ></el-table-column>
    <el-table-column
      align="center"
      property="optCodeContext"
      label="条码号"
      width="120"
      show-overflow-tooltip
    ></el-table-column>
    <el-table-column
      align="center"
      property="clientName"
      label="客户名称"
      width="120"
      show-overflow-tooltip
    ></el-table-column>
    <el-table-column
      label="位置"
      align="center"
      prop="place"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        <dict-tag
          :options="dict.type.quartz_common_location"
          :value="scope.row.place"
        />
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      property="height"
      label="长*宽"
      width="120"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        <span>{{ scope.row.height }}X{{ scope.row.width }}</span>
      </template>
    </el-table-column>
    <el-table-column
      align="center"
      property="type"
      label="原片类型"
      width="100"
      show-overflow-tooltip
    ></el-table-column>
    <el-table-column
      align="center"
      property="updateTime"
      label="更新时间"
      width="140"
      show-overflow-tooltip
    >
      <template slot-scope="scope">
        {{ scope.row.updateTime.substring(5) }}
      </template>
    </el-table-column>
    <el-table-column align="center" property="shelf" label="操作" width="200">
      <template slot-scope="scope">
        <el-button
          type="text"
          icon="el-icon-edit"
          slot="reference"
          v-hasPermi="['assembly:glass:edit']"
          @click="handleUpdate(scope.row, 1)"
          >报损</el-button
        >

        <el-button
          style="padding-left: 10px"
          type="text"
          v-hasPermi="['assembly:glass:edit']"
          icon="el-icon-error"
          @click="handleUpdate(scope.row, 2)"
          slot="reference"
          >异常</el-button
        >
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import { abnormal } from "@/api/production/quartz";
export default {
  dicts: [
    "quartz_glass_state",
    "quartz_common_location_search",
    "quartz_common_location",
  ],
  props: {
    tableData: {
      type: Array,
      default: () => {
        return [];
      },
    },
    showCameraBtn: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      valueString: false,
      isRelaod: true,
      loadTable: false,
    };
  },
  methods: {
    handlerCode(event) {
      let params =
        cameraList[event.lineIndex * 1 + 1] +
        "," +
        event.optCodeContext +
        ",1,0";
      if (params != null) {
        this.$prompt("请输入密码", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputPattern: /^5563$/,
          inputErrorMessage: "密码错误",
        })
          .then(({ value }) => {
            sendCameraText(params).then((res) => {
              if (res.code == 200) {
                this.$message({
                  type: "success",
                  message: res.msg,
                });
              } else {
                this.$message.error(res.msg);
              }
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入",
            });
          });
      } else {
        this.$message.warning("位置无扫码相机");
      }
    },
    reload() {
      this.$nextTick(() => {
        this.$emit("updateNumber");
      });
    },
    handleUpdate(row, state) {
     
      if (sessionStorage.getItem("showNewLosses") == "true" && state == 1) {
         console.log(this);
        this.$openLosses.showDialog([row], () => {
          this.$store.dispatch("listGlass").then((res) => {
            this.reload();
            this.loadTable = false;
            this.$emit("updateTable");
          });
        });
      } else {
        this.$prompt("请输入密码", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputPattern: /^5563$/,
          inputErrorMessage: "密码错误",
          inputType: "password",
        }).then(({ value }) => {
          this.loadTable = true;
          abnormal(row.id, state).then((res) => {
            this.$message({
              type: "success",
              message: "操作成功",
            });
            this.$store.dispatch("listGlass").then((res) => {
              this.reload();
              this.loadTable = false;
              this.$emit("updateTable");
            });
          });
        });
      }
    },
    handlerCode() {},
  },
  filters: {
    TimeInterval(timestamp) {
      //时间戳转化为天时分秒
      // 总秒数
      var second = Math.floor(timestamp / 1000);
      // 天数
      var day = Math.floor(second / 3600 / 24);
      // 小时
      var hr = Math.floor((second / 3600) % 24);
      // 分钟
      var min = Math.floor((second / 60) % 60);
      // 秒
      var sec = Math.floor(second % 60);
      if (second > 60) {
        return (
          (day ? day + "天" : "") +
          (hr ? hr + "小时" : "") +
          (min ? min + "分钟" : "")
        );
      } else {
        return sec + "秒";
      }
    },
  },
  computed: {
    orderTableData() {
      return this.tableData.sort((a, b) => {
        return a.orderId - b.orderId;
      });
    },
  },
};
</script>

<style>
.el-table .cell {
  padding: 0 !important;
  font-size: 15px;
}
.tipsText {
  font-size: 24px !important;
}
.el-table td.el-table__cell div {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
</style>
